package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.category.Category;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/2
 * description：
 */
@RestController
@RequestMapping("/admin/product/category")
@Tag(name = "分类管理模块")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/categoryList/{parentId}")
    @Operation(summary = "pid查询分类信息接口")
    public Result getCategoryByPid(@PathVariable Long parentId){
        List<Category> categoryList =  categoryService.getCategoryByPid(parentId);
        return Result.ok(categoryList);
    }

    @PostMapping("/importData")
    @Operation(summary = "excel文件上传接口")
    public Result importData(MultipartFile excel){
        categoryService.importData(excel);
        return Result.ok();
    }

    @GetMapping("/exportData")
    @Operation(summary = "excel文件下载接口")
    public Result exportData(HttpServletResponse response){
        categoryService.exportData(response);
        return Result.ok();
    }
}
